package com.example.musicdemo.adapter

import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.Toast
import com.example.musicdemo.model.AudioBean
import com.example.musicdemo.widget.PopListItemView

class PopAdapter(val list: List<AudioBean>, private var listener:PlayListListener? ) : BaseAdapter(){
    var mPosition:Int? = 0
    override fun getCount(): Int {
       return list.size
    }

    override fun getItem(position: Int): Any {
       return list[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }



    /**
     * 得到每一个子列表
     */
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
        var itemView:PopListItemView? = null
        if(convertView==null){
            itemView = PopListItemView(parent!!.context)
        }else{
            itemView = convertView as PopListItemView
        }
        itemView.setData(list[position])
        itemView.setOnClickListener{
            listener?.onPlay(position)
        }
        return itemView
    }

    interface PlayListListener{
        fun onPlay(position: Int)
        fun onDelete(position: Int)
    }




}